<?php
/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

if(!defined('TinyFW')) exit('Access denied!');

class tfFormFieldset extends tfFormElement {

    private $_legend = null;
    private $_delimeter = null;
    private $_elements = array();


    public function  __construct($caption='',$delimeter="&nbsp;", $legend_attr_arr='') {
        $this->setCaption($caption);
        $this->setAttr($legend_attr_arr);
        $this->setDelimeter($delimeter);
    }

    public function setDelimeter($delimeter) {
        $this->_delimeter = $delimeter;
    }
    
    public function getDelimeter() {
        return $this->_delimeter;
    }

    public function addElement($element) {
        $this->_elements[] = $element;
    }
    
    public function isContainer() {
        return true;
    }

    public function render() {

        $ret = "<fieldset>\r\n";
        if($this->getCaption() <> '') {
            $ret .= "<legend " . $this->getAttrStr() . ">" . $this->getCaption() . "</legend>\r\n";
        }
        $count = 0;
        foreach($this->_elements as $element) {

            if($count > 0 && $count < count($this->_elements)) {
                $ret .= $this->getDelimeter();
            }
            if($element->getCaption() != '') {
                $ret .= $element->getCaption() . "&nbsp;";
            }
            $ret .= $element->render();
            

            $count++;
        }

        $ret .= "</fieldset>\r\n";
        return $ret;
    }

    /*
    public function  __toString() {
        $this->render();
    }
    */

}

?>
